import requests

def download_pdf(url, save_path, headers):
    """
    下载PDF文件并保存到指定路径
    :param url: PDF文件的URL
    :param save_path: 保存路径
    """
    try:
        # 发送GET请求
        response = requests.get(url, headers=headers, stream=True, timeout=30, verify=True)

        # 检查请求是否成功
        if response.status_code == 200:
            # 以二进制模式打开文件并写入内容
            with open(save_path, 'wb') as file:
                file.write(response.content)
            print(f"PDF文件已成功下载并保存到 {save_path}")
        else:
            print(f"请求失败，状态码：{response.status_code}")
    except Exception as e:
        print(f"下载过程中发生错误：{e}")

# 示例URL
#pdf_url = "https://ecp.sgcc.com.cn/ecp2.0/ecpwcmcore//index/showPDF?filePath=cb8b39cf7814287a621788672c422b8ecd46f37d3200c2da33bf2cbd69385994b63a96f7c153184d605626aa46319b52e586e59ccb476c8612d43e4b8c969f183c67d8ce5c0221b1195e50d6eec82090ca2a76253fb7ae59134d4121e8272ce47c12aa3c4fe31a857c44e45357b48facbe439ae84a3a552acf4d6ec83833c02008d67c80694e0934bc71d4f69a47d0c80a7ded8d1d086d38df881469c2199f6f2e20d46ccdf099a4a4cd87aeca3fd7616fd0dea9607136c260e9714b01517a568d15c82768c4fc597d0fa28cbb8663d8|046fdb9bc9adfcffc3b35e6413f00cb50a732e7557c2a690b8afaa1f223ee749d7f49e6612caac85a2e08e90ca1224cdd7c121aa5c0bb0531173f47fe3ee482ca2ffeed81e9a84d8131fc87efa680887c4ddfad6f5525dfede05d605dcae6a48d4b86d95b3d4748a880a2a491934395c63138b02e8c318285879615671ccb30fc1ea1051be583b19323d6c1a16bccd0f9c309923c306461d19a3580ed5b30bb4d8fb"

# 保存路径
#save_path = "F:/ecp/1231.pdf"

# 模拟浏览器请求头
# headers = {
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
#     'host': 'ecp.sgcc.com.cn'
# }
# 调用下载函数
# download_pdf(pdf_url, save_path, headers)